package com.ruoyi.equipment.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.equipment.domain.EquipmentCheckPeriod;
import com.ruoyi.equipment.service.IEquipmentCheckPeriodService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 校验周期维护Controller
 * 
 * @author ruoyi
 * @date 2022-12-14
 */
@RestController
@RequestMapping("/equipment/period")
public class EquipmentCheckPeriodController extends BaseController
{
    @Autowired
    private IEquipmentCheckPeriodService equipmentCheckPeriodService;

    /**
     * 查询校验周期维护列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:period:list')")
    @GetMapping("/list")
    public TableDataInfo list(EquipmentCheckPeriod equipmentCheckPeriod)
    {
        startPage();
        List<EquipmentCheckPeriod> list = equipmentCheckPeriodService.selectEquipmentCheckPeriodList(equipmentCheckPeriod);
        return getDataTable(list);
    }

    /**
     * 导出校验周期维护列表
     */
    @PreAuthorize("@ss.hasPermi('equipment:period:export')")
    @Log(title = "校验周期维护", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, EquipmentCheckPeriod equipmentCheckPeriod)
    {
        List<EquipmentCheckPeriod> list = equipmentCheckPeriodService.selectEquipmentCheckPeriodList(equipmentCheckPeriod);
        ExcelUtil<EquipmentCheckPeriod> util = new ExcelUtil<EquipmentCheckPeriod>(EquipmentCheckPeriod.class);
        util.exportExcel(response, list, "校验周期维护数据");
    }

    /**
     * 获取校验周期维护详细信息
     */
    @PreAuthorize("@ss.hasPermi('equipment:period:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(equipmentCheckPeriodService.selectEquipmentCheckPeriodById(id));
    }

    /**
     * 新增校验周期维护
     */
    @PreAuthorize("@ss.hasPermi('equipment:period:add')")
    @Log(title = "校验周期维护", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody EquipmentCheckPeriod equipmentCheckPeriod)
    {
        return toAjax(equipmentCheckPeriodService.insertEquipmentCheckPeriod(equipmentCheckPeriod));
    }

    /**
     * 修改校验周期维护
     */
    @PreAuthorize("@ss.hasPermi('equipment:period:edit')")
    @Log(title = "校验周期维护", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody EquipmentCheckPeriod equipmentCheckPeriod)
    {
        return toAjax(equipmentCheckPeriodService.updateEquipmentCheckPeriod(equipmentCheckPeriod));
    }

    /**
     * 删除校验周期维护
     */
    @PreAuthorize("@ss.hasPermi('equipment:period:remove')")
    @Log(title = "校验周期维护", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(equipmentCheckPeriodService.deleteEquipmentCheckPeriodByIds(ids));
    }
}
